package com.hrbxlh.virtualization.controller;

import com.github.pagehelper.PageInfo;
import com.hrbxlh.virtualization.param.ContainerQueryParam;
import com.hrbxlh.virtualization.result.Result;
import com.hrbxlh.virtualization.service.ContainerService;
import com.hrbxlh.virtualization.util.SessionUtil;
import com.hrbxlh.virtualization.vo.ContainerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/container")
public class ContainerController {

    @Autowired
    private ContainerService containerService;

    /**
     * 分页查询容器列表
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result listContainers(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            ContainerQueryParam containerQueryParam) {

        containerQueryParam.setTeacherId(SessionUtil.getStuorteaId());
        PageInfo<ContainerVO> page = containerService.listContainersByPage(pageNum, pageSize, containerQueryParam);
        return Result.success(page);
    }

    /**
     * 批量删除容器
     *
     * @param ids 容器Id集合
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result deleteContainers(@RequestBody List<Long> ids) {
        containerService.deleteContainers(ids);
        return Result.success();
    }
}
